package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.model.dto.ShopPageQueryDTO;
import com.sky.model.entity.Shop;
import com.sky.model.vo.ShopVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShopMapper {

/*    @Select("select * from shop")*/
       // Page<ShopVO> pageQuery(ShopPageQueryDTO shopPageQueryDTO);

        /**
         * 插入商品数据
         * @param shop
         */

        @Insert("INSERT INTO Shop (Id, name, description, image, status, categoryName, categoryId, createTime, updateTime,url) " +
                "VALUES (#{Id}, #{name}, #{description}, #{image}, #{status}, #{categoryName}, #{categoryId}, #{createTime}, #{updateTime}, #{url})")

        void insert(Shop shop);

    /**
     * 修改商品信息
     * @param shop
     */
         void update(Shop shop);

        /**
         * 根据商品id删除对应的对象
         * @param Id
         * @return
         */
    @Delete("DELETE FROM Shop WHERE Id = #{Id}")
    void deleteById(Long Id);

    /**
     * 根据商品id查询对应的对象
     * @param id
     * @return
     */
    @Select("SELECT * FROM Shop WHERE Id = #{id}")
    Shop getById(Long id);


    /**
     * 商品信息展示
     * @param shopPageQueryDTO
     */
    Page<ShopVO> page(ShopPageQueryDTO shopPageQueryDTO);

    /**
     * 查询浏览历史
     *
     * @param userId
     * @return
     */
    Page<ShopVO> history(Long userId);

    /**
     * 查询收藏记录
     *
     * @param userId
     * @return
     */
    Page<ShopVO> starsList(Long userId);

    /**
     * 商品分页查询
     * @param shopPageQueryDTO
     * */
    long countShops(ShopPageQueryDTO shopPageQueryDTO);

    List<ShopVO> pageQuery(@Param("name") String name,
                           @Param("categoryId") Long categoryId,
                           @Param("status") Integer status,
                           @Param("offset") int offset,
                           @Param("limit") int limit);

    @Select("SELECT name FROM category WHERE id = #{categoryId}")
    String getCategoryName(Integer categoryId);
}
